package com.lancoo.answer.widget.combinationView;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lancoo.answer.R;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.util.RichTextUtils;

/**
 * Created by pengmi on 2021/12/14 10:58
 * Description:听写题等主观题查看评阅状态view
 */
public class WritingAnswerOriginalView extends RelativeLayout {


    public WritingAnswerOriginalView(Context context) {
        super(context);
        init(context);
    }

    public WritingAnswerOriginalView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public WritingAnswerOriginalView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }


    private void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.ev_layout_writing_answer_result,this);
        TextView tv_title=findViewById(R.id.tv_score_des);
        TextView tv_title1=findViewById(R.id.tv_answer_des);
        TextView tv_title2=findViewById(R.id.tv_my_answer_des);
        TextView tv_title3=findViewById(R.id.tv_my_score);
        String str="【";
        float v = tv_title.getPaint().measureText(str);
        tv_title.setTranslationX(-v/2);
        tv_title1.setTranslationX(-v/2);
        tv_title2.setTranslationX(-v/2);
        tv_title3.setTranslationX(-v/2);

        tv_title.setVisibility(GONE);
        tv_title3.setVisibility(GONE);
        tv_title2.setVisibility(GONE);
        findViewById(R.id.tv_my_answer).setVisibility(GONE);
        LayoutParams layoutParams = (LayoutParams) tv_title1.getLayoutParams();
        layoutParams.topMargin=0;
        tv_title1.setLayoutParams(layoutParams);
    }

    public void setChild(Child child){
        AnswerAnalysisView answerAnalysisView = findViewById(R.id.answer_analysis_view);
        answerAnalysisView.setAnalysis(child.getChildAnalysis());
        answerAnalysisView.setAlignmentType(1);
        TextView tv_answer=findViewById(R.id.tv_answer);
        String childAnswer = child.getChildAnswer();
        if(TextUtils.isEmpty(childAnswer)){
            tv_answer.setText(R.string.ev_item_null);
        }else{
            String replaceStr=tv_answer.getResources().getString(R.string.ev_standard_answer_replace);
            if(childAnswer==null){
                childAnswer="";
            }
            tv_answer.setText(RichTextUtils.getQueseAnswerStr(childAnswer.replace("$/",replaceStr).replace("$、","、"),child.getIsIndentChildAnswer(),false));
        }
    }


}
